package unclassified.simple;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class CountCommonWordsWithOneOccurrence_5922 {

    public int countWords(String[] words1, String[] words2) {
        Map<String, Integer> word1Map = new HashMap<String, Integer>();
        Map<String, Integer> word2Map = new HashMap<String, Integer>();
        for (String s : words1) {
            word1Map.put(s, word1Map.getOrDefault(s, 0) + 1);
        }
        for (String s : words2) {
            word2Map.put(s, word2Map.getOrDefault(s, 0) + 1);
        }
        int ans = 0;
        for (Map.Entry<String, Integer> entry : word2Map.entrySet()) {
            if (entry.getValue() != 1){
                continue;
            }
            if (word1Map.containsKey(entry.getKey())) {
                if (word1Map.get(entry.getKey()) == 1) {
                    ans++;
                }
            }
        }
        return ans;
    }
}
